import 'package:flutter/material.dart';

void main() => runApp(const SnackBarNoBuilerWidget());

class SnackBarNoBuilerWidget extends StatelessWidget {
  const SnackBarNoBuilerWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Flutter Demo",
      theme: ThemeData(
        primaryColor: Colors.blue,
      ),
      home: Scaffold(
          appBar: AppBar(title: const Text("Flutter UI基础Widget -- SnackBar")),
          body: const SnackBarWidget()),
    );
  }
}

class SnackBarWidget extends StatelessWidget {
  const SnackBarWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      child: const Text('Show SnackBar'),
      onPressed: () {
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
            content: Text('SnackBar'), duration: Duration(seconds: 5)));
      },
    );
  }
}
